﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 工艺流程步骤-加工过程(工序)
    /// </summary>
    public partial class CraftStepProcess : BusEntity
    {
        /// <summary>
        /// 工艺流程步骤ID
        /// </summary>
        public string CraftStepId { set; get; }
        /// <summary>
        /// 工序编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 工序名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 工序图标
        /// </summary>
        public string Icon { set; get; }
        /// <summary>
        /// 排序号
        /// </summary>
        public int Sort { set; get; }
    }

    public partial class CraftStepProcess : BusEntity
    {
        public CraftStep Step { set; get; }
        /// <summary>
        /// 加工工序下的工作
        /// </summary>
        public List<WorkshoStation> Stations { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class CraftStepProcessTypeConfig : BusEntityTypeConfig<CraftStepProcess>, IEntityTypeConfiguration<CraftStepProcess>
    {
        public override void Configure(EntityTypeBuilder<CraftStepProcess> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Step).WithMany(p => p.Process).HasForeignKey(p => p.CraftStepId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.CraftStepId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();            
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Icon).HasMaxLength(EntityDefinition.DefSmallColLen);
            #endregion

            #region 备注
            builder.HasComment("工艺流程步骤-加工过程(工序)");
            builder.Property(p => p.CraftStepId).HasComment("工艺流程步骤ID");            
            builder.Property(p => p.Code).HasComment("工序编码");
            builder.Property(p => p.Name).HasComment("工序名称");
            builder.Property(p => p.Icon).HasComment("工序图标");
            #endregion

            #region 种子数据
            builder.HasData(new CraftStepProcess() { Id = "0010", CraftStepId = "TTJG", Name = "工序1", Code = "0010", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0020", CraftStepId = "TTJG", Name = "工序2", Code = "0020", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0030", CraftStepId = "TTJG", Name = "工序3", Code = "0030", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0040", CraftStepId = "TTJG", Name = "工序4", Code = "0040", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0050", CraftStepId = "TTJG", Name = "工序5", Code = "0050", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0060", CraftStepId = "TTJG", Name = "工序6", Code = "0060", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0070", CraftStepId = "TTJG", Name = "工序7", Code = "0070", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "0080", CraftStepId = "TTJG", Name = "工序8", Code = "0080", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new CraftStepProcess() { Id = "LLHC_YPFJ", CraftStepId= "LLHC", Name = "叶片分拣", Code = "01.LLHC_YPFJ", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "LLHC_SXBFL", CraftStepId = "LLHC", Name = "扇形板发料", Code = "01.LLHC_SXBFL", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "LLHC_ZTBFL", CraftStepId = "LLHC", Name = "中筒板发料", Code = "01.LLHC_ZTBFL", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new CraftStepProcess() { Id = "PBJY_ZTPH", CraftStepId = "PBJY", Name = "锥筒拼焊", Code = "01.PBJY_ZTPH", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "PBJY_ZTSL", CraftStepId = "PBJY", Name = "中筒上料", Code = "02.PBJY_ZTSL", Icon = "dropbox", Sort = 2, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "PBJY_JY", CraftStepId = "PBJY", Name = "卷圆", Code = "03.PBJY_JY", Icon = "dropbox", Sort = 3, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new CraftStepProcess() { Id = "CXJYZ_ZFHJ", CraftStepId = "CXJYZ", Name = "纵缝焊接", Code = "01.CXJYZ_ZFHJ", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "CXJYZ_QZZD", CraftStepId = "CXJYZ", Name = "前锥组对", Code = "02.CXJYZ_QZZD", Icon = "dropbox", Sort = 2, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "CXJYZ_HZYZ", CraftStepId = "CXJYZ", Name = "后锥压装", Code = "02.CXJYZ_HZYZ", Icon = "dropbox", Sort = 2, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new CraftStepProcess() { Id = "TTJG_LSZD", CraftStepId = "TTJG", Name = "立式组对", Code = "01.TTJG_LSZD", Icon = "dropbox", Sort = 1, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "TTJG_NHFH", CraftStepId = "TTJG", Name = "内环缝焊", Code = "02.TTJG_NHFH", Icon = "dropbox", Sort = 2, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "TTJG_YPBD", CraftStepId = "TTJG", Name = "叶片摆搭", Code = "03.TTJG_YPBD", Icon = "dropbox", Sort = 3, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "TTJG_YPLXH", CraftStepId = "TTJG", Name = "叶片螺旋焊", Code = "04.TTJG_YPLXH", Icon = "dropbox", Sort = 4, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "TTJG_TTHM", CraftStepId = "TTJG", Name = "筒体合模", Code = "05.TTJG_TTHM", Icon = "dropbox", Sort = 5, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "TTJG_WHFH", CraftStepId = "TTJG", Name = "外环缝焊", Code = "06.TTJG_WHFH", Icon = "dropbox", Sort = 6, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new CraftStepProcess() { Id = "TTJG_RGBH", CraftStepId = "TTJG", Name = "人工补焊", Code = "07.TTJG_RGBH", Icon = "dropbox", Sort = 7, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new CraftStepProcess() { Id = "TTJC_TTJC", CraftStepId = "TTJC", Name = "筒体检测", Code = "01.TTJC_TTJC", Icon = "dropbox", Sort = 8, CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
